﻿@page "/Fin/OtherIncome/Create"
@using nERP.ViewModel.Fin.OtherIncomeVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <BootstrapInputGroupLabel @bind-Value="@Model.Entity.OtherIncomeCode" />
            <BootstrapInputGroup>
                <BootstrapInput @bind-Value="@Model.Entity.OtherIncomeCode"></BootstrapInput>
                <Button @ref="@btnSN" Icon="fas fa-plus" Text="@WtmBlazor.Localizer["Page.生成号码"]" OnClick="OnCreateSNAsync"></Button>
            </BootstrapInputGroup>
            <Select @bind-Value="@Model.Entity.CustomerId" Items="AllCustomers" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <Select @bind-Value="@Model.Entity.MakeUserId" Items="AllMakeUsers" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <DateTimePicker @bind-Value="@Model.Entity.InvoicesDate" />
            <Select @bind-Value="@Model.Entity.SettlementAccountId" Items="AllSettlementAccounts" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <Select @bind-Value="@Model.Entity.IncomeTypeId" Items="AllIncomeTypes" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <BootstrapInput @bind-Value="@Model.Entity.TotalPrice" />
            <BootstrapInput @bind-Value="@Model.Entity.Remark" />
            <WTUploadImage @bind-Value="@Model.Entity.InvoicesImage" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private OtherIncomeVM Model = new OtherIncomeVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Fin/OtherIncome/Create", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllCustomers = new List<SelectedItem>();
    private List<SelectedItem> AllMakeUsers = new List<SelectedItem>();
    private List<SelectedItem> AllSettlementAccounts = new List<SelectedItem>();
    private List<SelectedItem> AllIncomeTypes = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllCustomers = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherIncome/GetCustomers");
        AllCustomers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllMakeUsers = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherIncome/GetFrameworkUsers");
        AllMakeUsers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSettlementAccounts = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherIncome/GetSettlementAccounts");
        AllSettlementAccounts.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllIncomeTypes = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherIncome/GetDicFields其他收入类别");
        AllIncomeTypes.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });

        Model.Entity.InvoicesDate = DateTime.Now;
        Model.Entity.Status = nERP.Model.StatusTypeEnum.Unaudited;
        Model.Entity.MakeUserId = UserInfo.ITCode;
        await base.OnInitializedAsync();
    }
    private Button btnSN { get; set; }
    private async Task OnCreateSNAsync(MouseEventArgs e)
    {
        var SN = await GetNewSN2("其他收入", false);
        Model.Entity.OtherIncomeCode = SN;
        btnSN.SetDisable(true);
    }
}
